// pages/my/my.js
var app = getApp();
const getUserInfoUrl = '/User/myInfo';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    teacher_card:'',//导师名片地址
    my_card: '',//导师名片地址
    phone:'',//手机号 判断是否绑定过
    old_uid:'',//旧用户id，判断是否继承过以前就关系
    isLoading: 1,//是否显示加载中图标
    uid:0,//我的ID
    cash_coupon_num:0,//我的现金券个数
    user_balance: 0.00,//我的可提现余额
    vip_balance:0.00,//我的会员储值余额
    sys_status: 0,//控制审核状态
    user_nick: "",//用户昵称
    image: "",//用户头像
    user_level:0,// 级别 级别（0普通用户, 1普通粉丝, 2专属粉丝, 3普通会员, 4黄金会员, 5砖石会员）
    level_title: '',//级别描述
    my_get_pay_num:0,//我的待支付订单个数
    my_get_send_num:0,//我的待发货订单个数
    my_get_get_num:0,//我的待收货订单个数
    fans_get_pay_num:0,//粉丝待支付订单个数
    fans_get_send_num:0,//粉丝待发货订单个数
    fans_get_get_num:0//粉丝待收货订单个数
  },
  // 跳转我的导师页面
  goMyTeacher:function(){
    wx.navigateTo({
      url: '/pages/teacherCard/teacherCard?card=' + this.data.teacher_card,
    })
  },
  // 跳转我的名片页面
  goMyCard: function () {
    wx.navigateTo({
      url: '/pages/myCard/myCard?card=' + this.data.my_card,
    })
  },
  // 跳转首页
  goHome: function () {
    wx.reLaunch({
      url: '/pages/home/home',
    })
  },
  // 跳转购物车
  goBuyCar: function () {
    wx.reLaunch({
      url: '/pages/buyCar/buyCar',
    })
  },
  // 跳转搜索
  goSearch: function () {
    wx.reLaunch({
      url: '/pages/search/index',
    })
  },
  // 跳转我的
  goMy: function () {
    wx.reLaunch({
      url: '/pages/my/my',
    })
  },
  // 跳转邀请用户开店的页面
  goBindPhoneNum: function () {
    wx.navigateTo({
      url: '/pages/bindPhoneNum/bindPhoneNum?old_uid=' + this.data.old_uid + '&phone=' + this.data.phone,
    })
  },
  // 跳转邀请好友开店页面
  goSetUpShop:function(){
    wx.navigateTo({
      url: '/pages/setUpShop/setUpShop',
    })
  },
  // 跳转介绍页
  goIntroduce:function(){
    wx.navigateTo({
      url: '/pages/introduce/introduce',
    })
  },
  // 跳转提现页面
  goBalance:function(){
    wx.navigateTo({
      url: '/pages/enveWithdraw/enveWithdraw',
    })
  },
  // 跳转优惠券列表页面
  goCouponList:function(){
    wx.navigateTo({
      url: '/pages/CouponList/CouponList',
    })
  },
  // 跳转会员页面
  goVipRecharge:function(){
    wx.navigateTo({
      url: '/pages/vipRecharge/vipRecharge',
    })
  },
  // 跳转购物车页面
  goMyShopCar: function () {
    wx.navigateTo({
      url: '/pages/buyCar/buyCar',
    })
    console.log('跳转购物车');
  },
  // 跳转可提现的我的余额页面
  goMyBalance: function () {
    wx.navigateTo({
      url: '/pages/enveWithdraw/enveWithdraw',
    })
  },
  // 跳转我的消息列表页
  goMyNews: function () {
    wx.navigateTo({
      url: '/pages/newsList/newsList',
    })
  },
  // 跳转现金券页面
  goCashCoupon: function () {
    wx.navigateTo({
      url: '/pages/cashCoupon/cashCoupon?is_vip=1&uid=' + this.data.uid,
    })
  },
  // 跳转优惠券页面
  goCoupon: function () {
    wx.navigateTo({
      url: '/pages/coupon/coupon?is_vip=1',
    })
  },
  // 跳转我的现金券列表页面
  goCouponList: function () {
    wx.navigateTo({
      url: '/pages/couponList/couponList',
    })
  },
  // 跳转商家入驻页面
  goBusinessEnter: function () {
    wx.navigateTo({
      url: '/pages/businessEnter/businessEnter',
    })
  },
  // 跳转粉丝列表页面
  goFansList: function () {
    var _this = this;
    wx.navigateTo({
      url: '/pages/fansList/fansList'
    })
  },
  
  // 跳转收货地址页面
  goAddress: function () {
    wx.navigateTo({
      url: '/pages/addressList/addressList',
    })
  },
  // 跳转订单页面
  goOrderList: function (e) {
    // console.log(e);
    var current = e.currentTarget.dataset.current;
    var is_self = e.currentTarget.dataset.is_self;
    var is_bargain = e.currentTarget.dataset.is_bargain;
    wx.navigateTo({
      url: '/pages/orderList/orderList?current=' + current + '&is_self=' + is_self + '&is_bargain=' + is_bargain,
    })
  },
  // 获取我的订单信息
  getUserInfo: function () {
    var _this = this;
    var requestData = {
      token: _this.data.token,
      version: app.setConfig.version,
      type: app.setConfig.type
    }
    app.post(getUserInfoUrl, requestData, function (res) {
      if (res.code == 2000) {
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
        _this.setData({
          isLoading:0,
          my_card: res.data.my_card,
          teacher_card: res.data.teacher_card,
          phone: res.data.phone,
          old_uid: res.data.old_uid,
          uid:res.data.uid,
          user_nick: res.data.user_nick,
          image: res.data.image,
          user_level: res.data.level,
          level_title: res.data.level_title,
          my_get_pay_num: res.data.my_get_pay_num,
          my_get_send_num: res.data.my_get_send_num,
          my_get_get_num: res.data.my_get_get_num,
          fans_get_pay_num: res.data.fans_get_pay_num,
          fans_get_send_num: res.data.fans_get_send_num,
          fans_get_get_num: res.data.fans_get_get_num,
          user_balance: res.data.amount,
          vip_balance: res.data.packet_money,
          cash_coupon_num: res.data.cash_num
        })
      }else{
        wx.showToast({
          title: res.msg,
          icon: 'none',
          duration: 2000
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this;
    var configs = wx.getStorageSync('configs');
    _this.setData({
      sys_status: configs.sys_status
    })
  },
  onShow:function(){
    this.loop();
  },
  // 判断是否获取到token的值了
  loop: function () {
    var _this = this;
    var theToken = wx.getStorageSync("token");
    if (!theToken) {
      setTimeout(function () { _this.loop() }, 100);
    } else {
      _this.setData({
        token: theToken
      });
      _this.getUserInfo();
    }
  }
})